package com.qf.web.controller;/**
 * @author Administrator
 * @version v1.0
 * @date 2022/4/21
 */

import com.qf.domain.GoodsType;
import com.qf.service.GoodsTypeService;
import com.qf.service.impl.GoodsTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * projectName:Project_2202
 * author:
 * time:2022/4/21 15:38
 * description:
 */
@WebServlet("/addGoodsType")
public class AddGoodsTypeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        String goodsParent = request.getParameter("goodsParent");

        String typename = request.getParameter("typename");
        GoodsTypeService goodsTypeService = new GoodsTypeServiceImpl();
        GoodsType goodsType = new GoodsType();
        goodsType.setName(typename);
        goodsType.setParent(Integer.parseInt(goodsParent));
        goodsTypeService.insert(goodsType);

        response.sendRedirect("getGoodsType?method=show");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    public static void main(String[] args) {
        System.out.println("asd");
    }
}